from . import admin_bp
from celery_related.common_tasks.tasks import send_mail
from datetime import datetime, timedelta
from celery_related.delay_tasks.tasks import crwal_info


# 普通任务
@admin_bp.route('/mail/')
def mail():
    send_mail.delay("hello")
    return "Mail sent"


# 延迟任务
@admin_bp.route("/after/<t>", methods=["GET"])
def admin_after(t):
    eta = datetime.utcnow() + timedelta(seconds=5)
    result = crwal_info.apply_async(eta=eta)
    print(f"id为：{result.id} 的任务 - {t}s后准备开始干活了...")
    return "success"
